﻿@model DatNuocViet.Models.GetWebResourceResult
@{
    ViewBag.Title = "Dat Nuoc Viet";
}
<script type="text/javascript">
    var isFirstLoad = true;
    var target;
    $(document).ready(function () {
        $("#tabs").tabs();
        CKEDITOR.replace('DescriptionVn', { htmlEncodeOutput: true, width: "100%" });
        CKEDITOR.replace('DescriptionEn', { htmlEncodeOutput: true, width: "100%" });
        $("#dialog").dialog({ autoOpen: false, width: 400, height: 100 });
        $("#MenuContact").removeClass("dropdown").addClass("active");
    });
    function InsertImage() {
        if (CKEDITOR.currentInstance) {
            target = CKEDITOR.currentInstance.name;
            $("#dialog").dialog("open");
        }
        else
            alert('Vui lòng chọn văn bản');
    }
    function SubmitUploadImage() {
        var image = '<img alt="loading..." width="24px" height="24px" src="@Url.Content("~/Areas/Admin/Content/Images/loading.gif")" />';
        $("#loading").append(image);
        $("#ImgForm").submit();
    }
    function UploadImage_Complete() {
        if (isFirstLoad == true) {
            isFirstLoad = false;
            return;
        }
        document.getElementById("ImgForm").reset();
        var newImg = $.parseJSON($("#UploadTarget").contents().find("#jsonResult")[0].innerHTML);
        if (newImg.IsValid == false) {
            alert(newImg.Message);
            $("#loading").empty();
            return;
        }
        var imgHtml = CKEDITOR.dom.element.createFromHtml("<img src='" + newImg.ImagePath + "' alt='image'/>");
        if (target == "DescriptionVn") {
            CKEDITOR.instances['DescriptionVn'].insertElement(imgHtml);
        }
        if (target == "DescriptionEn") {
            CKEDITOR.instances['DescriptionEn'].insertElement(imgHtml);
        }
        $("#loading").empty();
        $("#dialog").dialog("close");
    }
</script>
<div class="contenttitle">
    <div class="titleplace">
        <span>Thông tin liên hệ</span>&nbsp;&nbsp;&nbsp;
        @if (ViewBag.message != null)
        {
            <span style="font-weight:600;color:Red;">@ViewBag.message</span>
        }
    </div>
    <div class="clear">&nbsp;</div>
</div>
<div class="contentitem">
    @using (Html.BeginForm("UpdateContact", "AdminHome", FormMethod.Post, new { id = "HomeForm", enctype = "multipart/form-data" }))
    {
        <input type="hidden" name="key" value="@Model.Key" />
        <div id="tabs">
            <ul>
                <li><a href="#tabs-1">Trang tiếng việt</a></li>
                <li><a href="#tabs-2">Trang tiếng anh</a></li>
            </ul>
            <div id="tabs-1">
                <textarea name="DescriptionVn" id="DescriptionVn" rows="1" cols="1">
                    @Html.Raw(Model.ValueVn)
                </textarea>
            </div>
            <div id="tabs-2">
                <textarea name="DescriptionEn" id="DescriptionEn" rows="1" cols="1">
                    @Html.Raw(Model.ValueEn)
                </textarea>
            </div>
        </div>
        <br />
        <div class="atributelabel">Trụ sở chính</div>
        <div class="atributeeditor">
            <input type="text" class="input250" name="Map" id="Map" value="@ViewBag.Map"/>
        </div>
        <div class="clear">&nbsp;</div>
        <p>
            <input type="button" value="Chèn hình ảnh" onclick="InsertImage();"/>
            <input type="submit" value="Lưu" />
        </p>
    }
</div>
<div id="dialog" title="Upload hình ảnh">
     @using (Html.BeginForm("UploadImage", "AdminHome", FormMethod.Post, new { enctype = "multipart/form-data", id = "ImgForm", name = "ImgForm", target = "UploadTarget" }))
     {
        <input type="hidden" name="folderName" id="folderName" value="upload" />
        <input type="file" name="UploadImage" id="UploadImage"/>
        <input type="button" value="Upload" onclick="SubmitUploadImage();" />
        <span id="loading"></span>
        <br />
        <small style="color:Red;">* Hình ảnh nhỏ hơn 1mb - Định dạng file jpg, gif, png</small>
     }
    <iframe id="UploadTarget" name="UploadTarget" onload="UploadImage_Complete();" style="position: absolute;left: -999em; top: -999em;"></iframe>    
</div>
